﻿using Xejen.Communication.Http.Configuration;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

namespace Xejen.Communication.Http.Abstract
{
    /// <summary>
    /// 表示String传输的<see langword="ContentType"/>内容策略
    /// </summary>
    /// <creator>marc</creator>
    internal class TextXmlContentStrategy : ContentStrategyBase, IHttpContentStrategy
    {
        /// <inheritdoc cref="TextXmlContentStrategy"/>
        /// <param name="config"><inheritdoc/></param>
        public TextXmlContentStrategy(HttpConfig config) : base(config) { }

        /// <inheritdoc/>
        public override HttpContent CreateHttpContent(object data)
        {
            string contentType = "text/xml";
            var content = new StringContent(data.ToString(), HttpConfig.Encoding);
            content.Headers.ContentType = new MediaTypeHeaderValue(contentType);
            return content;
        }
    }
}
